I computed realizations of multiple HODs for a few statistics in the darksky boxes. This notebook is gonna combine them into a jackknife covmat. It'll also add some estimate of the shape noise contribution.
In [ ]:
from matplotlib import pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()
import matplotlib.colors as colors
In [ ]:
cmap = sns.diverging_palette(240, 10, n=7, as_cmap = True)
In [ ]:
import numpy as np
from glob import glob
from os import path
from copy import deepcopy
In [ ]:
#shape_noise_covmat = np.load('/u/ki/swmclau2/Git/pearce/bin/covmat/shape_noise.npy')
shape_noise_covmat = np.load('./Hankel_transform/shape_noise.npy')
In [ ]:
print np.sqrt(np.diag(shape_noise_covmat))
In [ ]:
darksky_h = 0.7036893781978598
In [ ]:
output_dir = '/home/users/swmclau2/Git/pearce/bin/covmat/ds14_covmat_v2/'
In [ ]:
outputs = sorted(glob(path.join(output_dir, 'wp_ds_cic_darksky_obs_???_v2.npy')))
print len(outputs)
In [ ]:
N = len(outputs) # Should be 512, but a few may not have finished. Should make sure that those get reestarted, but likely not super important
all_outputs = np.zeros((N, 5, 2*18 + 14)) # num bins and num HODs
In [ ]:
2*18+14
In [ ]:
for i,output_file in enumerate(outputs):
if i == 0:
continue
output = np.load(output_file)
all_outputs[i] = output#.mean(axis = 0)
In [ ]:
all_outputs[0] = all_outputs[1:].mean(axis = 0)
In [ ]:
all_outputs.shape
In [ ]:
# undo a little h error of mine.
# WARNING i've since corrected this so it will no longer be necessary with new computations
all_outputs[:, :, 18:36]*=darksky_h**2
In [ ]:
rp_bins = np.logspace(-1.0, 1.6, 19)
cic_bins = np.round(np.r_[np.linspace(1, 9, 8), np.round(np.logspace(1,2, 7))] )
In [ ]:
cic_bins
In [ ]:
rp_points = (rp_bins[1:]+rp_bins[:-1])/2.0
cic_points = (cic_bins[1:]+cic_bins[:-1])/2.0
In [ ]:
for hod_idx in xrange(5):
color = 'b'
plt.plot(rp_points, (all_outputs[:,hod_idx, :18]).T, alpha = 0.1, color = color)
plt.loglog();
plt.show();
for hod_idx in xrange(4):
plt.plot(rp_points, (all_outputs[:,hod_idx, 18:36]).T, alpha = 0.1, color = 'g')
plt.loglog();
plt.show();
for hod_idx in xrange(4):
plt.plot(cic_points, all_outputs[:, hod_idx, 36:].T, alpha = 0.1, color = 'r')
plt.loglog();
plt.show();
In [ ]:
mean = all_outputs.mean(axis = 0)
In [ ]:
def cov_to_corr(cov):
std = np.sqrt(np.diag(cov))
denom = np.outer(std, std)
return cov/denom
In [ ]:
np.zeros(len(cic_bins)-1)
In [ ]:
# from my HOD mock on planck
planck_y = np.array([3.67046115e+03, 2.68587097e+03, 1.86704547e+03, 1.33957041e+03,
9.30848932e+02, 6.45761466e+02, 4.44257796e+02, 3.02746585e+02,
2.09074584e+02, 1.52330606e+02, 1.14548962e+02, 8.90682088e+01,
6.94674502e+01, 5.30164183e+01, 3.92803031e+01, 2.74329581e+01,
1.77901804e+01, 1.03439673e+01, 8.12760963e+01, 6.53112366e+01,
5.11718897e+01, 3.92571969e+01, 2.95591990e+01, 2.18952850e+01,
1.59647482e+01, 1.14391216e+01, 7.99808271e+00, 5.44370980e+00,
3.61379155e+00, 2.33425032e+00, 1.55491234e+00, 1.10505031e+00,
8.02946770e-01, 6.28019530e-01, 5.08370232e-01, 4.01059480e-01,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0. ])
In [ ]:
mean = all_outputs.mean(axis = 0)
R =(all_outputs - mean)
corr = np.zeros((R.shape[2], R.shape[2]))
yerr_ratio = np.zeros((R.shape[2]))
for i in xrange(R.shape[1]):
c= R[:,i].T.dot(R[:,i])/(N-1)
corr += cov_to_corr(c)
yerr_ratio += np.sqrt(np.diag(c))/mean[i]
corr/= (mean.shape[0])#*(N-1)
yerr_ratio/=(mean.shape[0])
In [ ]:
print yerr_ratio
In [ ]:
plt.imshow(corr, cmap = cmap, vmin=-1)
In [ ]:
yerr = yerr_ratio*planck_y
cov = corr*np.outer(yerr, yerr)
In [ ]:
cov.shape
In [ ]:
np.min(cov)
In [ ]:
plt.imshow(cov_to_corr(shape_noise_covmat), cmap = 'viridis')
In [ ]:
print(cov_to_corr(shape_noise_covmat))[:5, :5]
In [ ]:
full_cov = deepcopy(cov)
full_cov[18:36][:, 18:36] = full_cov[18:36][:, 18:36]+ shape_noise_covmat
In [ ]:
corr = cov_to_corr(cov)
full_corr = cov_to_corr(full_cov)
In [ ]:
fig = plt.figure(figsize = (10, 5))
plt.subplot(121)
im = plt.imshow(corr, cmap = cmap, vmin = -1)
plt.colorbar(im);
plt.subplot(122)
im = plt.imshow(full_corr, cmap = cmap, vmin = -1)
plt.colorbar(im);
plt.show()
In [ ]:
fig = plt.figure(figsize = (15, 5))
plt.subplot(131)
im = plt.imshow(corr[18:36][:, 18:36], cmap = cmap, vmin = -1)
plt.colorbar(im);
plt.subplot(132)
im = plt.imshow(cov_to_corr(shape_noise_covmat), cmap = cmap, vmin = -1)
plt.colorbar(im);
plt.subplot(133)
im = plt.imshow(full_corr[18:36][:, 18:36], cmap = cmap, vmin = -1)
plt.colorbar(im);
plt.show()
In [ ]:
np.sqrt(np.diag(full_corr)[18:36])
In [ ]:
plt.plot(rp_points, np.sqrt(np.diag(cov)[18:36]), label = 'Sim')
plt.plot(rp_points,np.sqrt(np.diag(shape_noise_covmat)), label = 'Shape')
plt.plot(rp_points,np.sqrt(np.diag(full_cov)[18:36]), label = 'Total')
#plt.xscale('log')
plt.loglog();
plt.legend(loc = 'best')
In [ ]:
print full_corr[30:30+5][:, 30:30+5]
In [ ]:
np.save('/home/users/swmclau2/Git/pearce/bin/covmat/wp_ds_full_covmat.npy', full_cov[:36][:, :36])
np.save('/home/users/swmclau2/Git/pearce/bin/covmat/wp_full_covmat.npy', full_cov[:18][:, :18])
np.save('/home/users/swmclau2/Git/pearce/bin/covmat/ds_full_covmat.npy', full_cov[18:36][:, 18:36])
np.save('/home/users/swmclau2/Git/pearce/bin/covmat/wp_ds_sim_covmat.npy', cov[:36][:, :36])
In [94]:
plt.plot(rp_points, rp_points*np.sqrt(np.diag(full_cov[:18, :18]) ), label = 'wp')
#plt.plot(rp_points, np.sqrt(np.diag(shape_noise_covmat) ), label = 'Shape')
#plt.plot(rp_points, np.sqrt(np.diag(cov[18:36, 18:36]) ), label = 'ds')
plt.plot(rp_points, rp_points*np.sqrt(np.diag(full_cov[18:36, 18:36]) ), label = 'ds')
plt.loglog()
plt.legend(loc='best')
Out[94]:
In [95]:
print np.sqrt(np.diag(full_cov[:36][:,:36]))
In [96]:
print np.sqrt(np.diag(full_cov[18:36, 18:36]) )
In [97]:
#emu covs
emu_cov_fnames = ['/home/users/swmclau2/Git/pearce/bin/optimization/wp_hod_emu_cov_lpw.npy',
'/home/users/swmclau2/Git/pearce/bin/optimization/ds_hod_emu_cov_lpw.npy']
In [98]:
emu_cov = np.zeros_like(full_cov[:36][:, :36])
for i, fname in enumerate(emu_cov_fnames):
emu_cov[i*18:(i+1)*18][:, i*18:(i+1)*18] = np.load(fname)
In [99]:
emu_corr = cov_to_corr(emu_cov)
In [100]:
plt.imshow(emu_corr, cmap = cmap, vmin = -1)
Out[100]:
In [101]:
full_emu_cov = full_cov[:36][:, :36] + emu_cov
In [102]:
print np.sqrt(np.diag(full_emu_cov[:36][:,:36]))
In [103]:
full_emu_corr = cov_to_corr(full_emu_cov)
In [104]:
plt.imshow(full_emu_corr, cmap = cmap, vmin = -1)
Out[104]:
In [105]:
mean[:,:18].mean(axis=0)
Out[105]:
In [ ]:
In [106]:
np.sqrt(np.diag(full_emu_cov[:18, :18]) )/mean[:-1, :18].mean(axis=0)
Out[106]:
In [112]:
plt.plot(rp_points, np.sqrt(np.diag(full_emu_cov[:18, :18]) ), label = 'Total')
plt.plot(rp_points, np.sqrt(np.diag(cov[:18, :18]) ), ls = '--', label = 'Sim')
plt.plot(rp_points, np.sqrt(np.diag(emu_cov[:18, :18]) ), ls = ':', label = 'Emu')
plt.plot(rp_points, np.sqrt(np.diag(full_emu_cov[18:36, 18:36])) , label = 'ds', color ='r')
plt.plot(rp_points, np.sqrt(np.diag(cov[18:36, 18:36]) ), color = 'r', ls = '--')
plt.plot(rp_points, np.sqrt(np.diag(emu_cov[18:36, 18:36]) ), color = 'r', ls = ':')
plt.plot(rp_points, np.sqrt(np.diag(shape_noise_covmat)), color = 'r', ls = '-.')
#plt.ylabel('Delta Sigma Unc')
plt.xlabel('r [Mpc]')
plt.loglog()
plt.legend(loc='best')
Out[112]:
In [110]:
#plt.plot(rp_points, np.sqrt(np.diag(cov[18:36, 18:36]) ), label = 'ds')
plt.plot(rp_points, np.sqrt(np.diag(full_emu_cov[18:36, 18:36])) , label = 'Total', color ='r')
plt.plot(rp_points, np.sqrt(np.diag(cov[18:36, 18:36]) ), color = 'g', label = 'Sim', ls = '--')
plt.plot(rp_points, np.sqrt(np.diag(emu_cov[18:36, 18:36]) ), color = 'r', ls = ':', label = 'Emu')
plt.plot(rp_points, np.sqrt(np.diag(shape_noise_covmat)), color = 'b', label = 'Shape Noise',ls = '-.')
plt.ylabel('Delta Sigma Unc')
plt.xlabel('r [Mpc]')
plt.loglog()
plt.legend(loc='best')
Out[110]:
In [109]:
0.7**2
Out[109]:
In [ ]:
In [ ]:
In [ ]: